﻿isPollActive 				= false

addEvent('onPollStart')
addEventHandler('onPollStart', root, function() isPollActive = true end)
addEvent('onPollEnd')
addEventHandler('onPollEnd', root,function() isPollActive = false end)

function checkForVotespam(message)
	if isPollActive then
		if isVotespam(message) then -- die vote spammers
			local g_Red, g_Green, g_Blue = getPlayerNametagColor(source)
			outputChatBox(getPlayerName(source) .. ": #E0D0B0" .. message, source, g_Red, g_Green, g_Blue, true) -- show it only for spammer
			cancelEvent()
		end
	end
end
addEventHandler( "onPlayerChat", root, checkForVotespam)

function isVotespam(message) -- I don't know how to write regex for this ;)
	local result = {}
	for l in string.gmatch(message, "%d") do
		local number = tonumber(l)
		if number then
			if not result[number] then result[number] = 1 else result[number] = result[number] + 1 end
			if result[number] >= math.floor(#message/2) then return true end -- if matches more than a half of a message
		end
	end
	return false
end